const SITEURL = document.location.protocol+"//" +window.location.host+"/";
// Initialize your app
var myApp = new Framework7({
    modalTitle: "提示",
    modalButtonOk: "确定",
    modalButtonCancel: "取消",
    modalPreloaderTitle: "加载中...",
    modalUsernamePlaceholder: "用户名",
    modalPasswordPlaceholder: "密码",
    tapHold: true //enable tap hold events
});

// Export selectors engine
var $$ = Dom7;

// Add views
var view1 = myApp.addView('#view-1');
var view2 = myApp.addView('#view-2', {
    // Because we use fixed-through navbar we can enable dynamic navbar
    dynamicNavbar: true
});
var view3 = myApp.addView('#view-3');
var view4 = myApp.addView('#view-4');

if( !getCookie("APP_LOGIN_SUCCESS") ){
    myApp.modalLogin('Authentication required', function (user_name, password) {
        $$.post("/app/login",
            {
                user_name:user_name,
                password:password,
            }
            ,function(d){
            d = JSON.parse(d);
            if(d.code === 1000){
                myApp.alert("登录成功");
                setTimeout(function(){
                    location.reload();},1*1000)
            }else{
                myApp.alert("密码错误");
                setTimeout(function(){
                    location.reload();},1*1000)
            }
        });
    },function(){
        location.reload();
    });
}

function url_(s){
    return SITEURL+s;
}
function sendCmd(id){
    $$.get( url_('send_cmd'),
    {
        id:id,
    }
    ,function(d){
        d = JSON.parse(d);
        myApp.alert(d.msg);
    });


}
function getCookie(name)
{
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

    if(arr=document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}

/////////////录音操作